import { Component, Inject } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Storage } from '@ionic/storage';

// service
import { ContactsService } from '../providers/utils/contacts.service';
import * as PageConstant from '../constant/pageConstant';
import { TabsPage } from '../pages/tabs/tabs';

@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  rootPage: any= PageConstant.TabsPage;
  // rootPage: string = PageConstant.LoginPage;
  // rootPage: string = PageConstant.BorrowOrderPage;
  // rootPage: string = PageConstant.TestPage;

  constructor(
    public platform: Platform,
    public statusBar: StatusBar,
    public splashscreen: SplashScreen,
    public storage: Storage,
    @Inject('auth') private authService,
    private contcatsService: ContactsService,
  )
  {
    // this.rootPage= Constant
    this.initializeApp();
  }

  initializeApp()
  {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      // this.statusBar.styleDefault();
      this.statusBar.styleLightContent();
      this.splashscreen.hide();

      // 获取通讯录
      this.contcatsService.getContcatsList();
      // this.contcatsService.getLocalTestList();
      // this.initRootPage();
      // this.initHasLogin();
    });
  }

  /*** 初始化选择是否为第一次登录
  * */
  initRootPage()
  {
    this.storage.get(PageConstant.TabsPage)
      .then(value => {
        if(value){
          this.rootPage= TabsPage;
        }else { // 第一次进入
          this.storage.set(PageConstant.TabsPage, 'enter');
          this.rootPage= PageConstant.WelcomePage;
        }
      });
  }

  /*** 初始化是否为登录状态
  * */
  initHasLogin()
  {
    this.authService.checkHasLogin();
  }
}
